package org.huanglei.account.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import android.content.Context;
import android.util.Log;

public class DatabaseToSD {
	
	public static void copyDatabaseToSD(Context context, String databaseName){

		  String fileName="/data/data/"+context.getPackageName()+"/databases/"+databaseName;

		  File file=new File("/data/data/"+context.getPackageName());

		  for(String path:file.list()){
		      Log.e("Database2SD",path);
		  }

		  File databaseFile=new File(fileName);

		  try {

				FileInputStream fis = new FileInputStream(databaseFile);
				FileChannel inChannel=fis.getChannel();
				FileOutputStream fos=new FileOutputStream(new File("/sdcard/"+databaseName));
				FileChannel outChannel=fos.getChannel();
				outChannel.transferFrom(inChannel, 0, inChannel.size());
				fis.close();
				fos.close();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}

}
